import 'package:car_map/mode/spuare_type_mode.dart';
import 'package:car_map/page/routers/fluro_navigator.dart';
import 'package:car_map/page/statisticspage/statistics_router.dart';
import 'package:car_map/utils/image_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

///统计
class StatisticsPage extends StatefulWidget {
  @override
  _statisticsPage createState() => _statisticsPage();
}

class _statisticsPage extends State<StatisticsPage> {
  List<SpuareTypeModel> spuareTypeList;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getSpuareTypeList();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text(
          '统计',
        ),
        centerTitle: true,
      ),
      body: Container(
        padding: EdgeInsets.only(top: 10.0, bottom: 10.0),
        child: ListView.builder(
          itemBuilder: (context, index) {
            return _listTitle(spuareTypeList[index]);
          },
          itemCount: spuareTypeList.length,
        ),
      ),
    );
  }

  Widget _listTitle(SpuareTypeModel spuareTypeModel) {
    return Container(
      decoration: BoxDecoration(
          border:
              Border(bottom: BorderSide(color: Colors.black12, width: 0.5))),
      child: ListTile(
        title: Text(spuareTypeModel.title),
        leading: Image.asset(
          ImageUtils.getImgPath(spuareTypeModel.urlPath),
          width: ScreenUtil().setWidth(40.0),
          height: ScreenUtil().setHeight(40.0),
        ),
        trailing: Icon(Icons.navigate_next),
        onTap: () {
          switch (spuareTypeModel.currentIndex) {
            case 0: //历程统计
              NavigatorUtils.push(context, StatisticsRouter.mileageCountPage,
                  replace: false);
              break;


            case 2://加油统计
              NavigatorUtils.push(context, StatisticsRouter.addoilCountPage,
                  replace: false);
              break;

            case 4://加油统计
              NavigatorUtils.push(context, StatisticsRouter.ignitionPage,
                  replace: false);
              break;

            case 5://加油统计
              NavigatorUtils.push(context, StatisticsRouter.temperaturePage,
                  replace: false);
              break;
          }
        },
      ),
    );
  }

  List<SpuareTypeModel> getSpuareTypeList() {
    spuareTypeList = new List();
    spuareTypeList.add(new SpuareTypeModel(
        title: '里程统计', urlPath: 'statistics/ic_route', currentIndex: 0));
    spuareTypeList.add(new SpuareTypeModel(
        title: '报警统计', urlPath: 'statistics/ic_police', currentIndex: 1));
    spuareTypeList.add(new SpuareTypeModel(
        title: '加油统计', urlPath: 'statistics/ic_flow', currentIndex: 2));
    spuareTypeList.add(new SpuareTypeModel(
        title: '漏油统计', urlPath: 'statistics/ic_oilspill', currentIndex: 3));
    spuareTypeList.add(new SpuareTypeModel(
        title: '点火统计', urlPath: 'statistics/ic_ignition', currentIndex: 4));
    spuareTypeList.add(new SpuareTypeModel(
        title: '温度统计', urlPath: 'statistics/ic_temperature', currentIndex: 5));
    spuareTypeList.add(new SpuareTypeModel(
        title: '百公里油耗统计',
        urlPath: 'statistics/ic_consumption',
        currentIndex: 6));

    spuareTypeList.add(new SpuareTypeModel(
        title: '停车统计', urlPath: 'square/ic_parking', currentIndex: 7));
    spuareTypeList.add(new SpuareTypeModel(
        title: 'CAN信息统计', urlPath: 'home/ic_statistics', currentIndex: 8));
    spuareTypeList.add(new SpuareTypeModel(
        title: '驾驶行为信息统计', urlPath: 'square/ic_driving', currentIndex: 9));
    spuareTypeList.add(new SpuareTypeModel(
        title: '故障码个数统计',
        urlPath: 'statistics/ic_malfunction',
        currentIndex: 10));
    spuareTypeList.add(new SpuareTypeModel(
        title: '主动安全报警统计', urlPath: 'statistics/ic_safety', currentIndex: 11));
    spuareTypeList.add(new SpuareTypeModel(
        title: '怠速统计', urlPath: 'statistics/ic_speed', currentIndex: 12));
  }
}
